// 学生相关接口
import {request} from '../utils/request'

const studentApi = {
  examSearch: '/exam/getExamsOfStudent',
  getExamById: '/exam/getExamById',
  getPaperQuestionOrder: '/exam/getPaperQuestionOrder',
  getQuestionByOrder: '/exam/getQuestionByOrder',
  getQuestionById: '/question/queryById',
  postPaper: '/exam/handInAnswerPaper'
}

// 查找学生参加的所有考试
export function examSearch () {
  return request({
    url: studentApi.examSearch,
    method: 'get',
    params: {
      studentId: sessionStorage.getItem('studentId')
    }
  })
}

// 通过id查询考试
export function getExamById (id) {
  return request({
    url: studentApi.getExamById,
    method: 'get',
    params: {
      examId: id
    }
  })
}

// 通过考试id查询试卷题目分布
export function getPaperQuestionOrder (examid, stuNum) {
  return request({
    url: studentApi.getPaperQuestionOrder,
    method: 'get',
    params: {
      examId: examid,
      studentNumber: stuNum
    }
  })
}

// 根据题目位置找到题目
export function getQuestionByOrder (examId, groupNum, num, stuNum) {
  return request({
    url: studentApi.getQuestionByOrder,
    method: 'get',
    params: {
      examId: examId,
      groupNumber: groupNum,
      number: num,
      studentNumber: stuNum
    }
  })
}

// 根据id获取题目
export function getQuestionById (id) {
  return request({
    url: studentApi.getQuestionById,
    method: 'get',
    params: {
      questionId: id
    }
  })
}

// 交卷
export function postPaper (examid, studentid, answerList) {
  return request({
    url: studentApi.postPaper,
    method: 'post',
    params: {
      examId: examid,
      studentId: studentid
    },
    data: answerList
  })
}
